var missleSpeed = 8;

if( instance_exists( basicEnemy_par ) )
{
    var enemy1 = instance_nearest( self.x, self.y, enemy1_obj );
    var enemy2 = instance_nearest( self.x, self.y, Enemy2_obj );
    var enemy1Spwn = instance_nearest( self.x, self.y, enemy1spwn_obj );
    
    if( !instance_exists( enemy1 ) && !instance_exists( enemy2 ) && instance_exists ( enemy1Spwn ) )
    {
        move_towards_point( enemy1Spwn.x, enemy1Spwn.y, missleSpeed );
    }
    else if( !instance_exists( enemy1 ) && instance_exists( enemy2 ) && !instance_exists ( enemy1Spwn ) )
    {
        move_towards_point( enemy2.x, enemy2.y, missleSpeed );
    }
    else if( instance_exists( enemy1 ) && !instance_exists( enemy2 ) && !instance_exists ( enemy1Spwn ) )
    {
        move_towards_point( enemy1.x, enemy1.y, missleSpeed );
    }
    else
    {
        if( distance_to_object( enemy1 ) < distance_to_object( enemy2 ) && distance_to_object( enemy1 ) < distance_to_object( enemy1Spwn ) )
        {
            move_towards_point( enemy1.x, enemy1.y, missleSpeed );
        }
        else if( distance_to_object( enemy2 ) < distance_to_object( enemy1 ) && distance_to_object( enemy2 ) < distance_to_object( enemy1Spwn ) )
        {
            move_towards_point( enemy2.x, enemy2.y, missleSpeed );
        }
        else if( distance_to_object( enemy1Spwn ) < distance_to_object( enemy1 ) && distance_to_object( enemy1Spwn ) < distance_to_object( enemy2 ) )
        {
            move_towards_point( enemy1Spwn.x, enemy1Spwn.y, missleSpeed );
        }
    }
    self.image_angle = direction;
}
else if( instance_exists( basicObs_par ) )
{
    var asteroid1 = instance_nearest( self.x, self.y, asteroid1_obj );
    var asteroidLrg = instance_nearest( self.x, self.y, asteroidLrg_obj );
    
    if( !instance_exists(asteroid1) && instance_exists(asteroidLrg) )
    {
        move_towards_point( asteroidLrg.x, asteroidLrg.y, missleSpeed );
    }
    else if( instance_exists(asteroid1) && !instance_exists(asteroidLrg) )
    {
        move_towards_point( asteroid1.x, asteroid1.y, missleSpeed );
    }
    else
    {
        if( distance_to_object( asteroid1 ) < distance_to_object( asteroidLrg ) )
        {
            move_towards_point( asteroid1.x, asteroid1.y, missleSpeed );
        }
        else
        {
            move_towards_point( asteroidLrg.x, asteroidLrg.y, missleSpeed );
        }
    }
    
    self.image_angle = direction;
}
else
{
    self.vspeed = -missleSpeed;
    self.image_angle = direction;
}